function block_items_dragsort_bind() {
    $('#clip-frame-ul, #note-view-content ul').dragsort(
        { dragSelector: '.block-item-drag-handler, .clip-item-drag-handler', 
        dragBegin: function(event) {
            global.ue.save_content();
            global.ue.close();
            event.stopPropagation();
        },
        dragEnd: function(event) {
            var li_dragged = $(this);
            //drag to/in clip
            if (li_dragged.parent().parent().attr('id') == 'clip-stack' 
                && li_dragged.find('.block-item-drag-handler').length!=0) 
            {
                //drag item to clip
                if (li_dragged.find('.clip-item-drag-handler').length==0) {
                    $(this).find('.block-item-wrapper').hide();
                    var cnt = cut_content(this, 10);
                    $(this).append('<div class="clip-item-drag-handler in-frame">'+cnt+'</div>');
                    var id = $(this).parent().parent().parent().parent().attr('id').toString().split('_')[0];
                    remove_block_do(id);

                    block_items_dragsort_bind()
                } else { //drag item in clip
                    //pass
                }
            } 
            else if (li_dragged.parent().parent().attr('id') != 'clip-stack' 
                && li_dragged.find('.block-item-drag-handler').length!=0 ) 
            {
                //drag item from clip
                if (li_dragged.find('.clip-item-drag-handler').length!=0) {
                    $(this).find('.block-item-wrapper').show();
                    $(this).find('.clip-item-drag-handler').remove();
                    //block_items_dragsort_bind()
                } else {
                    //pass
                }
            }
            global.note_status = 1 ;
        }, 
        dragBetween: true 
    });
}

function block_items_mousedown_bind() {
    $('.block-item').unbind();        
    $('.block-item').bind('mousedown', function(event){ 
        //prevent the bubble, but not default events
        event.stopPropagation();
    });    
}

function block_item_contents_click_bind() {
    $('.block-item-content').unbind();
    $('.block-item-content').click(function (event){
        global.ue.close();
        global.ue.create_editor(this);
        var id = $(this).attr('id').split('_')[0].toString();
        global.crr_block_id = id;
        global.modified_block_ids[id]=1;
        switch_toolbar('#note-edit-bar');
        event.stopPropagation();
    });
}

function block_item_remove_btn_click_bind () {
    $('.block-item-remove-btn').unbind();    
    $('.block-item-remove-btn').click(function (){
        var id = $(this).parent().parent().parent().parent().attr('id').toString().split('_')[0];
        if(confirm('Are you sure you want to permanently delete this note?'))
        {
            remove_block_do(id);
        }
    });
}

function block_items_hover_bind () {
    $('.block-item').hover(function () {
            $(this).find('.block-small-btn-base').fadeIn();
        },
        function () {
            $(this).find('.block-small-btn-base').fadeOut();
        }
    );
}

function block_tag_btns_click_bind () {
    $('.block-item-tag-btn').click(function () {
            var id = $(this).parents('.block-item').attr('id').toString().split('_')[0];
            var tag_bar = $(this).parent().parent();
            var tags = []
            tag_bar.find('.block-item-tag').each(function () {
                tags.push($(this).text());
            })
            var ret = prompt('Edit note tags', tags.join(','));
            if (ret != null) {
                tags = []
                tags.push('[')
                $.each(ret.split(','),function(i,n) {
                    tags.push('"');
                    tags.push(n);
                    tags.push('"');
                    tags.push(',')
                });
                tags.pop(); //last ","
                tags.push(']');
                save_block_tag_do(id, tags.join(''));
            }
        }
    );
}


